<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>新增明细配送</title>
	<link rel="stylesheet" href="css/reset.css">
	<link rel="stylesheet" href="css/product.css">
	<link rel="stylesheet" href="css/select-big.css">
	<style>
		.content-btn {
		    margin: 0 16px;
		}
		.product-child-content{
			width: 970px;
			margin: 0 auto;
		}
		.product-child-content .content-btn {
		    margin: 0;
		}
		.content-table-two tbody tr td input{
			width: 80%;
			height: 30px;
			line-height: 30px;
			background: #F9FBFF;
			border: 1px solid #ecf2f7;
			border-radius: 15px;
			text-align: center;
		}
		.icon-delImg{
			display: inline-block;
		    background: url(images/close-1.png)no-repeat;
		    width: 25px;
		    height: 25px;
		    cursor: pointer;
		}
		.icon-delImg:hover{
			background: url(images/close-1.png)no-repeat 0 -27px;
		}
	</style>
</head>
<body>
<div class="main-content">
	<form dataHref = "/expressInformation/save">
		<input type = "hidden" name = "type" value = "0">
		<div class="main-bg1">
			<div class="content-btn bot-line">
				<a class="icon-back" href="contractDistribution1.html"></a><span class="title-info-a">快速配送</span>
			</div>
			<div class="content-list">
				
				<table class="content-table-newservice" cellspacing="0" cellpadding="0">
					<tbody>
						<tr>
							<td><span class="info-red"><font color="red">*</font>收件人部门：</span></td>
							<td>
								<div id = "sign" class = "fuzzy-query" dataUrl = "/org/selectAllDeptTree" dataname = "departmentname" datavalue = addressee lablename = "parentName" valuename = "parentId"></div>
							</td>
						</tr>
						<tr>
							<td><span class="info-red"><font color="red">*</font>快递公司：</span></td>
							<td><select class="chooseSelect" id="single2">
								<option value="1">顺丰快递</option>
								<option value="2">圆通快递</option>
								<option value="3">申通快递</option>
								<option value="4">韵达快递</option>
								<option value="5">汇通快递</option>
								<option value="6">邮政EMS</option>	
								<option value="7">自取</option>
							</select></td>
						</tr>
						<tr>
							<td><span class="info-red"><font color="red">*</font>快递单号：</span></td>
							<td><input type="text" name = "tracknumber" class = "required"></td>
						</tr>
						<tr>
							<td><span class="info-red"><font color="red">*</font>印刷厂：</span></td>
							<td><select class="chooseSelect" id="single3">
								<option value="0">请选择</option>
								<option value="1">杭州印刷厂</option>
								<option value="2">廊坊印刷厂</option>
								<option value="3">总部发放</option>
							</select></td>
						</tr>
						<tr>
							<td>描述：</td>
							<td><textarea name="" id="" cols="30" rows="3"></textarea></td>
						</tr>
					</tbody>
				</table>
			</div>
			<div class="product-child-content">
				<div class="content-info">
					<div class="content-btn bot-line">
						<span class="title-info">纸质合同信息</span>
					</div>
					<table class="tableOrder content-table-two matop" cellspacing="0" cellpadding="0" >
						<thead>
							<tr>
								<td style="width:100px;">项目编号</td>
								<td style="width:250px;">项目名称</td>
								<td style="width:100px;">可配送数量</td>
								<td style="width:100px;">本次配送数量</td>
								<td style="width:150px;">合同编号</td>
								<td style="width:100px;">操作</td>
							</tr>
						</thead>
						<tbody id = "body">
							<!-- <tr>
								<td>24355345</td>
								<td>中融国富-稳隆1号契约基金</td>
								<td>10</td>
								<td><input type="text" placeholder="1"></td>
								<td><input type="text" placeholder="1"></td>
								<td><i class="icon-delImg" onclick="del()"></i></td>
							</tr>
							<tr>
								<td>24355345</td>
								<td>中融国富-稳隆1号契约基金</td>
								<td>10</td>
								<td><input type="text" placeholder="1"></td>
								<td><input type="text" placeholder="1"></td>
								<td><i class="icon-delImg" onclick="del()"></i></td>
							</tr>
							<tr>
								<td>24355345</td>
								<td>中融国富-稳隆1号契约基金</td>
								<td>10</td>
								<td><input type="text" placeholder="1"></td>
								<td><input type="text" placeholder="1"></td>
								<td><i class="icon-delImg" onclick="del()"></i></td>
							</tr>
							<tr>
								<td>24355345</td>
								<td>中融国富-稳隆1号契约基金</td>
								<td>10</td>
								<td><input type="text" placeholder="1"></td>
								<td><input type="text" placeholder="1"></td>
								<td><i class="icon-delImg" onclick="del()"></i></td>
							</tr>
							<tr>
								<td><input type="text"></td>
								<td><input type="text"></td>
								<td>10</td>
								<td><input type="text"></td>
								<td><input type="text"></td>
								<td><i class="icon-delImg" onclick="del()"></i></td>
							</tr> -->
						</tbody>
					</table>
					<!-- <p style="line-height:40px;"><i class="btn-operation">新增合同信息</i></p> -->
					<button class="save-btn matop">保存</button>
				</div>
			</div>
		</div>
	</form>
</div>
	<script src="js/jquery-3.2.1.min.js"></script>
	<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
	<script src="js/select.jquery.js"></script>
	<script type="text/javascript" src = "js/util.js"></script>
	<script type="text/javascript" src = "js/table.js"></script>
	<script type="text/javascript" src = "js/fuzzy-query.js"></script>
	<script type="text/javascript" src = "js/allProduct.js"></script>
	<script>
		function getHeight(){
			var myiframeH=$(".main-content").height();
			var _parent=$(window.parent.document);
        	_parent.find('body').css('height',(myiframeH+150)+'px');
			_parent.find('.main-position').css('height',(myiframeH+100)+'px');
    	};
    	$('.main-content').resize(function(){
			getHeight();
		});
    	function validateCallback(){
    		var bo = true;
    		if(!$("div.fuzzy-query").getVal()){
    			parent.layer.msg("请选择收件部门");
    			return false;
    		}
    		var $tr = $("#body").find("tr");
    		var length = $tr.length;
    		if(length < 1){
    			parent.layer.msg("没有合同需要配送");
    			return false;
    		}
    		for(var i = 0 ; i < length ; i++){
    			debugger
    			var can = $($tr[i]).find("td").eq(3).text();
    			var sr = $($tr[i]).find("td").eq(4).find("input").val();
    			var code = $($tr[i]).find("td").eq(5).find("input").val().split(";");
    			if(isNaN(sr)){
    				parent.layer.msg("本次配送数量只能输入数字");
    				return false;
    			}
    			if(sr * 1 > can * 1){
    				parent.layer.msg("本次配送数量不能超过可配送数量");
    				return false;
    			}
    			if(sr * 1 != code){
    				parent.layer.msg("请输入合理的配送编号，配送编号按';'切割后的长度应该与本次配送数量相等。")
    				return false;
    			}
    		}
    		return bo;
    	} 
    	function del(my){
    		$(my).parent().parent().remove();
    	}
    	function buildHtml(printer,department){
    		var param = new FormData();
    		param.append("printer",printer);
    		param.append("department",department);
    		$.ajax({
		        type: 'post',
		        url:baseUrl + "/contractInbound/findList",
		        contentType: false,  
		        processData: false, 
		        async: false,
		        data:param
			}).done(function(data){
				var list = data.list;
				var $body = $("#body");
				var html = "";
				for(var i = 0 ; i < list.length  ; i++){
					html += "<tr><td><input type = 'hidden' name = 'id' value = '" + list[i].id + "'>" + list[i].projectcode + "</td><td>" + list[i].projectname
					+"</td><td>" + list[i].total + "</td><td><input type = 'text' name = 'inbounds[" + i + "].dispatchnumber' placeholder = '" + list[i].total + "'></td>"
					+"<td><input type = 'text' name = 'inbounds[" + i + "].remark'></td><td><i class = 'icon-delImg' onclick = 'del(this)'></td></tr>";
				}
				$body.empty();
				$body.append(html);
				//console.log(data);
			});
    	}
    	$(document).ready(function(){
    		/* $("#single1").change(function(){
    			var department = $(this).val();
    			var printer = $("#single3").val();
    			buildHtml(printer,department);
    		}); */
			$("#single3").change(function(){
	    		var printer = $(this).val();
	    		var department = $("#sign").getVal();
	    		if(!department){
	    			parent.layer.msg("请选择部门");
	    			return;
	    		}
	    		buildHtml(printer,department);
	    	});
    	})
	</script>
	<script src="js/jquery-validation/1.11.0/jquery.validate.min.js" type="text/javascript"></script>
	<script type="text/javascript" src = "js/submit.js"></script>
	<script type="text/javascript" src = "js/validate.js"></script>
</body>
</html>